<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>分页</title>
</head>
<body>
	<?php
	$con = mysql_connect("localhost","root","root");
	$pagesize = 1;
	mysql_select_db("pro",$con);
	$rs = mysql_query("select count(*) from mytable",$con);
	$myrow = mysql_fetch_array($rs);
	$numrows = $myrow[0];

	$pages = intval($numrows/$pagesize);
	if($numrows%$pagesize) $pages++;

	if(isset($_GET['page'])){
		$page = intval($_GET['page']);
	}else{
		$page = 1;
	}

	$offset = $pagesize *($page-1);
	$rs=mysql_query("select * from myTable order by id asc limit $offset,$pagesize",$con);
	if ($myrow = mysql_fetch_array($rs))
		{$i = 0;
			?>
			<table>
			<tr>
			<td>
			<p align="center">标题</p></td>
			<td>
			<p align="center">时间</p></td>
			</tr>
			<?php
			do{
				$i++;
				?>
				<tr>
				<td><?=$myrow["news_title"]?></td>
				<td><?=$myrow["news_cont"]?></td>
				</tr>
				<?php
			}
			while($myrow = mysql_fetch_array($rs));
			echo "</table>";
			}
			echo "<div align='center'>共有"."{$pages}"."页(".$page."/".$pages.")";

			$first=1;
            $prev=$page-1;
            $next=$page+1;
            $last=$pages;
            if ($page > 1){
            	echo '<a href="sa.php?page='.$first.'">首页</a>';
            	echo '<a href="sa.php?page='.$prev.'">上一页</a>';
			}
			if ($page < $pages){
            	echo '<a href="sa.php?page='.$next.'">下一页</a>';
            	echo '<a href="sa.php?page='.$last.'">尾页</a>';
			}












// 			 for($i=1;$i<$page;$i++){
// 			 	echo "<a href='sa.php?page=".$i."'>[".$i."]</a>";
// 			     //echo "[".$page."]";
// }
// 			 for($i = $page+1;$i<=$pages;$i++)
// 			 	echo "<a href='sa.php?page=".$i."'>[".$i."]</a>";
// 			 echo "</div>";
















			?>













			

</body>
</html>


















